package com.lce.service.impl;

import com.lce.beans.Chart;
import com.lce.beans.Leave;
import com.lce.beans.User;
import com.lce.dao.ManagerDao;
import com.lce.dao.UserDao;
import com.lce.service.UserService;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl implements UserService {

    private SqlSessionTemplate sqlSessionTemplate;

    //setSqlSessionTemplate模板
    @Autowired
    public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    @Override
    public void addUser(User user) {
        UserDao userDao = sqlSessionTemplate.getMapper(UserDao.class);
        userDao.addUser(user);
        System.out.println("添加成功！");
    }

    @Override
    public User login(User user) {
        UserDao userDao = sqlSessionTemplate.getMapper(UserDao.class);
        User user1 = userDao.login(user);
        return user1;
    }

    @Override
    public User getUser(int uid) {
        UserDao userDao = sqlSessionTemplate.getMapper(UserDao.class);
        User user1 = userDao.getUser(uid);
        return user1;
    }

    @Override
    public List getAllUser() {
        UserDao userDao = sqlSessionTemplate.getMapper(UserDao.class);
        List<User> list= userDao.getAllUser();
        return list;
    }

    @Override
    public void updateUser(User user) {
        UserDao userDao = sqlSessionTemplate.getMapper(UserDao.class);
        userDao.updateUser(user);
    }

    @Override
    public void addLeave(Leave leave) {
        UserDao userDao = sqlSessionTemplate.getMapper(UserDao.class);
        userDao.addLeave(leave);
    }

    @Override
    public int getApprovalId(int did) {
        UserDao userDao = sqlSessionTemplate.getMapper(UserDao.class);
        int getApprovalId=userDao.getApprovalId(did);
        return getApprovalId;
    }

    @Override
    public List<Chart> getChart() {
        UserDao userDao = sqlSessionTemplate.getMapper(UserDao.class);
        List<Chart> charts=userDao.getChart();
        System.out.println("userserive检查"+charts);
        return charts;
    }


}
